package com.zxr.demo.controllers;

import com.zxr.demo.commom.bo.AddUserBO;
import com.zxr.demo.commom.bo.LoginBO;
import com.zxr.demo.commom.vo.UserVO;
import com.zxr.demo.service.UserService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Validated
public class UserController {

    @Autowired
    public UserService userService;

    //登录
    @PostMapping("/login")
    public String login(@RequestBody @Valid LoginBO loginBO) {
        return userService.login(loginBO);
    }

    //检查授权
    @GetMapping("/is_auth")
    public Boolean isAuth(@RequestParam String name) {
        return userService.isAuth(name);
    }

    //退出
    @PostMapping("/logout")
    public Boolean logout(@RequestHeader("Authorization") String authorization) {
        return userService.logout(authorization);
    }

    //查询
    @RequestMapping("/get_users")
    public List<UserVO> getUsers() {
        return this.userService.getUser();
    }

    //添加
    @PostMapping("/add_name")
    public Boolean addName(@RequestBody @Valid AddUserBO addUserBO) {
        return userService.addUser(addUserBO);
    }
}
